package com.chuanggou.framework.exception;

import entity.Result;
import entity.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 处理异常的类
 * @Author: wzw
 * @Date: 2020/12/7 19:54
 * @version: 1.8
 */
@ControllerAdvice  //全局捕获异常类
public class BaseExceptionHandler {
    /**
     * 异常处理
     */
    @ExceptionHandler(value = Exception.class)//开启异常注解
    @ResponseBody //响应注解
    public Result error(Exception e){
        e.printStackTrace();
        return new Result(false, StatusCode.ERROR,e.getMessage());
//        return new Result(false, StatusCode.ERROR,"程序出错了");
    }

}
